package com.yikaiye.android.yikaiye.dialog;

import android.content.Context;
import android.view.Gravity;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;

import com.yikaiye.android.yikaiye.R;
import com.yikaiye.android.yikaiye.databinding.DialogLoadingBinding;

public class LoadingDialog extends BaseCommonBottomDialog<DialogLoadingBinding> {

    private RotateAnimation rotateAnimation;

    public LoadingDialog(Context context) {
        super(context);
    }

    @Override
    protected void initView() {
        rotateAnimation = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        rotateAnimation.setRepeatCount(-1);//设置旋转重复次数，可以为-1表示不停止
        rotateAnimation.setDuration(1500);//设置持续时间，注意这里是每一圈的持续时间，如果上面设置的圈数为3，持续时间设置1000，则图片一共旋转3秒钟
        rotateAnimation.setInterpolator(new LinearInterpolator());//设置动画匀速改变。相应的还有AccelerateInterpolator、DecelerateInterpolator、CycleInterpolator等
        mBinding.ivLoading.setAnimation(rotateAnimation);//设置imageview的动画，也可以myImageView.startAnimation(myAlphaAnimation)
    }

    public void setCancelable(boolean isCancelable){
        setCancelable(isCancelable);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_loading;
    }

    @Override
    protected int getGravity() {
        return Gravity.CENTER;
    }

    protected int getAnimations() {
        return R.style.prompt_progress_dialog_dimenabled;
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    public void dismiss() {
        super.dismiss();
        if (rotateAnimation != null) {
            rotateAnimation.cancel();
        }
    }
}
